import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-09-02
 * Time: 0:03
 */
class Solution5 {
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String,List<String>> hash = new HashMap<>();

        // 1.把异位词进行分组
        for(String s : strs) {
            char[] tmp = s.toCharArray();
            Arrays.sort(tmp);
            String key = new String(tmp);

            if(!hash.containsKey(key)) {
                hash.put(key,new ArrayList());
            }
            hash.get(key).add(s);
        }
        // 2.提取结果
        return new ArrayList(hash.values());
    }
}
